package com.justech.mes.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author Administrator
 * @version 1.0
 * @create 2018-06-17 20:45
 **/
@Configuration
public class RabbitmqConfig {
    public static final String QUEUE_INFORM_MES = "queue_inform_mes";
    public static final String EXCHANGE_TOPICS_INFORM = "exchange_topics_inform";

    //声明交换机
    @Bean(EXCHANGE_TOPICS_INFORM)
    public FanoutExchange EXCHANGE_TOPICS_INFORM() {
        //durable(true) 持久化，mq重启之后交换机还在
        return new FanoutExchange(EXCHANGE_TOPICS_INFORM);
    }

    //声明QUEUE_INFORM_EMAIL队列
    @Bean(QUEUE_INFORM_MES)
    public Queue QUEUE_INFORM_EMAIL() {
        return new Queue(QUEUE_INFORM_MES);
    }

    //ROUTINGKEY_EMAIL队列绑定交换机，指定routingKey
    @Bean
    public Binding BINDING_QUEUE_INFORM_EMAIL(@Qualifier(QUEUE_INFORM_MES) Queue queue,
                                              @Qualifier(EXCHANGE_TOPICS_INFORM) FanoutExchange exchange) {
        return BindingBuilder.bind(queue).to(exchange);
    }
}
